package com.situ.shopuser.controller;

import com.situ.shoplook.common.model.Product;
import com.situ.shoplook.common.service.CategoryService;
import com.situ.shoplook.common.service.ProductService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author:yzy
 * @date:2024/9/4
 */
@Controller
@RequestMapping
public class UrlController {
    @DubboReference
    private ProductService productService;
    @DubboReference
    private CategoryService categoryService;

    @GetMapping("/{url}")
    public String show(@PathVariable(value = "url") String url, Map<String, Object> map) {
        if (url.equals("shop1")) {
            List<Integer> categoryIds = new ArrayList<>();
            categoryIds = categoryService.findChildren(2);
            System.out.println("categoryIds:" + categoryIds);
            List<Product> products = productService.findByIds(categoryIds);
            map.put("products", products);
        }else {
            List<Product> products = productService.findAllProducts();
            map.put("products", products);
        }
        List<Product> bestProducts = productService.findBest();
        map.put("bestProducts", bestProducts);
        System.out.println("bestProducts:" + bestProducts);
        return url;
    }
}
